package org.mch.swingm.core;

import java.awt.Component;
import java.io.File;

import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JList;

public class MCompanyLogoListCellRenderer<E> extends DefaultListCellRenderer {
	private static final long serialVersionUID = 5935554523289117104L;

	public static ImageIcon folder = new ImageIcon(MCompanyLogoListCellRenderer.class.getResource("/resource/images/folder.gif"), "文件夹");
	public static ImageIcon file = new ImageIcon(MCompanyLogoListCellRenderer.class.getResource("/resource/images/filelist.gif"), "文件");

	public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		Component retValue = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

		if (value != null && value instanceof File) {
			if (((File) value).isDirectory()) {
				setIcon(folder);
			} else if (((File) value).isFile()) {
				setIcon(file);
			}
		}
		return retValue;
	}
}